﻿module Common

open System.IO

 
let getDirFiles( dir:string) =
    Directory.GetFiles dir

let getDir (filePath:string) =
    if filePath.Contains(".") then
        let (lst,i) =filePath |> Seq.fold (fun (indexs,i) c -> if c = '\\' then (i::indexs,i+1) else (indexs,i+1) ) ([],0)
        filePath.Substring(0,lst.Head)
    else filePath
let getFileName (fileFullPath:string) =
        let (lst,i) =fileFullPath |> Seq.fold (fun (indexs,i) c -> if c = '\\' then (i::indexs,i+1) else (indexs,i+1) ) ([],0)
        fileFullPath.Substring(lst.Head+1)

let (|BothHave|_|) (a:string,b:string) = 
    if a.[a.Length-1] = '\\' && b.[0]='\\' then
        Some(a+b.Substring(1))
    else None
let (|BothNone|_|) (a:string,b:string) = 
    if a.[a.Length-1] <> '\\' && b.[0]<>'\\' then
        Some(a+"\\"+b)
    else None
let conbindPath path1 path2 =
    match path1,path2 with
    | BothHave str ->str
    | BothNone str ->str
    | _ -> path1+path2